package cn.tedu._05mvcboot03.common.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    @ApiModelProperty("状态码")
    private Integer state;
    @ApiModelProperty("提示消息")
    private String message;
    @ApiModelProperty("返回数据")
    private Object data;

    public JsonResult(StatusCode statusCode){
        this.state =    statusCode.getState();
        this.message = statusCode.getMessage();
    }

    public JsonResult(StatusCode statusCode, Object date){
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = date;
    }

    public static JsonResult ok(Object data){
        return new  JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }

    public static JsonResult ok(){
        return ok(null);
    }
}
